package com.orange.off.cloud.cloudoff.activity;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

import com.orange.off.cloud.cloudoff.R;
import com.orange.off.cloud.cloudoff.app.MyApplication;
import com.orange.off.cloud.cloudoff.utils.SPUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

public class WelcomeActivity extends Activity {
    @Bind(R.id.welcome_img)
    ImageView welcomeImg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.welcome_activity);
        ButterKnife.bind(this);
        welcomeImg = (ImageView) findViewById(R.id.welcome_img);
        AlphaAnimation alphaAnim = new AlphaAnimation(0.3f, 1.0f);
        alphaAnim.setDuration(3000);
        welcomeImg.setAnimation(alphaAnim);
        alphaAnim.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                open();
            }
        });

    }

    private void open() {
        boolean is = getSharedPreferences(getString(R.string.version_name), 0).getBoolean(HelpActivity.ISFIRST_KEY, false);
        String user = (String) SPUtil.get(this, "username", "");
        //        String pwd = (String) SPUtil.get(getActivity(), "password", "");
        //        String num = PhoneUtils.getPhoneNumber(getActivity());
        MyApplication.aid = (String) SPUtil.get(this, "userid", "");
        if (is) {
            if (TextUtils.isEmpty(user)) {
                Intent intent = new Intent(getApplicationContext(), IntermediaryActivity.class);
                intent.putExtra("type", IntermediaryActivity.LOGIN);
                startActivity(intent);
            } else {
                Intent intent = new Intent(this, MainActivity.class);
                startActivity(intent);
            }

        } else {

            Intent intent = new Intent(getApplicationContext(), HelpActivity.class);
            startActivity(intent);
        }
        finish();
        overridePendingTransition(R.anim.anim_enter, R.anim.anim_exit);
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

}
